#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define FRONT_MAX 35  // 前区最大数值
#define BACK_MAX 12   // 后区最大数值

void select_numbers(int *selected, int count, int max, int *exclude, int exclude_count) {
    int i = 0, num;
    while (i < count) {
        num = rand() % max + 1; // 随机生成 1 到 max 的数字
        int valid = 1;
        for (int j = 0; j < i; j++) {  // 检查是否重复
            if (selected[j] == num) {
                valid = 0;
                break;
            }
        }
        for (int j = 0; j < exclude_count; j++) {  // 检查是否与胆码冲突
            if (exclude[j] == num) {
                valid = 0;
                break;
            }
        }
        if (valid) {
            selected[i++] = num;
        }
    }
}

void dantuo_play(int *front_dan, int front_dan_count, int *front_tuo, int front_tuo_count,
                 int *back_dan, int back_dan_count, int *back_tuo, int back_tuo_count) {
    printf("前区胆码：");
    for (int i = 0; i < front_dan_count; i++) {
        printf("%02d ", front_dan[i]);
    }
    printf("\n");

    printf("前区拖码：");
    for (int i = 0; i < front_tuo_count; i++) {
        printf("%02d ", front_tuo[i]);
    }
    printf("\n");

    printf("后区胆码：");
    for (int i = 0; i < back_dan_count; i++) {
        printf("%02d ", back_dan[i]);
    }
    printf("\n");

    printf("后区拖码：");
    for (int i = 0; i < back_tuo_count; i++) {
        printf("%02d ", back_tuo[i]);
    }
    printf("\n");
}

int main() {
    srand((unsigned int)time(NULL));

    // 用户输入胆码数量和拖码数量
    int front_dan_count = 2;  // 前区胆码数
    int front_tuo_count = 3;  // 前区拖码数
    int back_dan_count = 1;   // 后区胆码数
    int back_tuo_count = 1;   // 后区拖码数

    // 分配空间存储胆码和拖码
    int front_dan[front_dan_count];
    int front_tuo[front_tuo_count];
    int back_dan[back_dan_count];
    int back_tuo[back_tuo_count];

    // 随机生成胆码和拖码
    select_numbers(front_dan, front_dan_count, FRONT_MAX, NULL, 0);
    select_numbers(front_tuo, front_tuo_count, FRONT_MAX, front_dan, front_dan_count);
    select_numbers(back_dan, back_dan_count, BACK_MAX, NULL, 0);
    select_numbers(back_tuo, back_tuo_count, BACK_MAX, back_dan, back_dan_count);

    // 打印胆拖组合
    printf("您的胆拖玩法号码如下：\n");
    dantuo_play(front_dan, front_dan_count, front_tuo, front_tuo_count,
                back_dan, back_dan_count, back_tuo, back_tuo_count);

    return 0;
}
